<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    输入手机号<input type="text">  <button>获取验证码</button>


    <script>
        //获取按钮文本对象
        const btnObj = document.querySelector("button")
        //设置倒计时时间
        let time = 3;
        //按钮添加事件
        btnObj.addEventListener("click",function(){
            btnObj.disabled = true;
            const setTime1 = setInterval(function(){
                if(time!=0){
                btnObj.innerHTML = '等待'+time+'秒可以重新发送'
                time--;
            } else{
                //取消定时器        取消很重要
                clearInterval(setTime1)

                btnObj.innerHTML = '获取验证码'
                time = 3;
                btnObj.disabled = false
            }
            },1000)
          
        })
    </script>
</body>
</html>